<template>
	<!-- 添加或修改责任书对话框 -->
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="500px" append-to-body>
		<el-form ref="form" :model="formData" :rules="formRules" label-width="80px">
			<el-form-item label="保密人员" prop="userId">
				<person-select v-model="formData.userId" :list="checkedUsers" :disabled="isDisabled"></person-select>
			</el-form-item>
			<el-form-item label="责任书" prop="file">
				<duty-upload v-model="formData.file"></duty-upload>
			</el-form-item>
		</el-form>
		<template slot="footer">
			<el-button type="primary" @click="handleSubmitData()">确定</el-button>
			<el-button @click="visible = false">取消</el-button>
		</template>
	</el-dialog>
</template>

<script>
import dutyUpload from './uploader';
import formMixins from '../common/formMixins';
import { getDuty, addDuty, updateDuty } from '@/api/personnal/duty';
export default {
	mixins: [formMixins],
	components: { dutyUpload },
	data() {
		return {
			formName: '责任书',
			formRules: {
				userId: { required: true, message: '请选择保密人员', trigger: 'change' },
				file: { required: true, message: '请上传责任书', trigger: 'change' }
			}
		};
	},
	computed: {
		detailFunction() {
			return eval(getDuty);
		},
		callFunction() {
			return eval(this.addOrEdit ? addDuty : updateDuty);
		}
	},
	watch: {
		'formData.fileId': {
			handler(val) {
				if (!val) return false;
				this.$set(this.formData, 'file', [
					{
						url: this.formData.fileUrl,
						name: this.formData.fileName,
						size: this.formData.fileSize,
						suffix: this.formData.fileFileSuffix
					}
				]);
			}
		}
	},
	watch: {
		userDetail(data) {
			this.$set(this.formData, 'userName', data.name);
		}
	},
	methods: {
		//格式化请求参数
		formatRequestParams() {
			let params = { ...this.formData };
			let fileData = params.file[0];
			params['fileUrl'] = fileData.url;
			params['fileSize'] = fileData.size;
			params['fileName'] = fileData.name;
			params['fileFileSuffix'] = fileData.suffix;
			return params;
		}
	}
};
</script>
<style>
.el-month-table td.current:not(.disabled) .cell {
	line-height: 34px;
	box-sizing: border-box;
	border: solid 1px #1890ff;
}
</style>
